export function useLinePoint () {
  function newPoint(lat:number,lng:number,id:number){//放置新的航线点
    const Point = {
      id,
      geometry: {
          coordinates: [lat, lng],
          type: 'Point',
      },
      type: 'Feature',
      properties: {
          h: 130,
      },
      rotation:{
        x:90,
        y:0,
        z:-40
      },
      action:[]
    }
    return Point
  };
  function newLine(pos2:any,pos1:any,id:number){ //创建新的航线 
    const angle = changeAngle(pos1,pos2)
    const line = {
      id,
        type: "Feature",
        properties: {
            type: 0,
            ratio: 0.0577,
            lineWidthRatio: 1,
        },
        geometry: {
            type: "LineString",
            coordinates: [
                pos1,
                pos2
            ]
        },
        angle:angle

    }

    return line
  };
  function changeAngle(position1:any,position2:any){
    let valLng = position2[0] - position1[0];
    let valLat = position2[1] - position1[1];
    // 返回一个绝对值
    let absoluteLng = Math.abs(valLng);
    let absoluteLat = Math.abs(valLat);
    // 取得三角形的斜边
    let hypotenuse = Math.hypot(absoluteLng, absoluteLat);
    // 计算弧度
    let radina = Math.acos(absoluteLng / hypotenuse);
    // 计算角度
    let angle = Math.floor(radina * 180 / Math.PI);
    // console.log("两坐标点计算出的角度为：", angle)
    // 计算出标记点真正旋转的角度
    if (valLng > 0) {
      if (valLat < 0) {
        // 第三象限
        angle = 0- angle;
      } else {
        // 第二象限
        angle = angle;
      }
    } else {
      if (valLat > 0) {
        //第四象限
        angle = 180- angle;
      } else {
        // 第一象限
        angle = -180 + angle;
      }
    }
    return angle
  }
  
  return {
    newPoint,
    newLine,
    changeAngle
  }
}
